<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>CSS Regions: mouse events don't trigger for region children</title>
	<link rel="author" title="Mihai Balan" href="mailto:mibalan@adobe.com">
	<link rel="help" href="http://www.w3.org/TR/css3-regions/#the-flow-into-property">
	<link rel="help" href="http://www.w3.org/TR/css3-regions/#the-flow-from-property">
	<meta name="assert" content="Children of regions (elements with flow-from) are removed from the document flow and JavaScript event handlers set on them should not fire">
	<meta name="flags" content="dom interact">
	<style>
	body {
		margin: 0;
		padding: 20px;
	}
	p {
		margin: 0;
	}
	.box {
		width: 200px;
		height: 200px;
		float: left;
		margin: 20px;
	}
	#source {
		background-color: lightcyan;
	}
	#source p {
		width: 100%;
		height: 100px;
		background-color: green;
		flow-into: flow;
	}
	#region {
		background-color: yellow;
		flow-from: flow;
	}
	#region p {
		margin-top: 100px;
		width: 100%;
		height: 100px;
		background-color: red;
	}
	#result {
		clear: both;
		font-weight: bold;
	}
	.pass {
		color: green;
	}
	.fail {
		color: red;
	}
	</style>
</head>
<body>
	<ol>
		<li>Mouse over the green rectangle and click</li>
		<li>Mouse over the yellow rectangle and click</li>
		<li>You should see "PASS" appearing below</li>
		<li>You should not see any red, or the word "FAIL"</li>
	</ol>
	<div id="source" class="box">
		<p></p>
	</div>
	<div id="region" class="box">
		<p></p>
	</div>
	<div id="result" class=""></div>
	<script type="text/javascript">
	var contentCalls = 0,
		regionCalls = false;

	function setResult(value) {
		var tag = document.querySelector("#result");
		tag.innerHTML = value;
		tag.classList.add(value.toLowerCase());
	}

	function contentEventHandler(evt) {
		contentCalls++;
		
		if (contentCalls == 3) {
			setResult("PASS");
			finishTest();
		}
	}

	function regionChildEventHandler(evt) {
		regionCalls = true;
		setResult("FAIL");
		finishTest();
	}

	function finishTest() {
		if (window.testRunner) {
			testRunner.notifyDone();
		}
	}

	function runScriptedTest() {
		if (window.testRunner) {
			testRunner.dumpAsText();
			testRunner.waitUntilDone();

			var boxLocation = document.querySelector("#region").getBoundingClientRect();
			eventSender.mouseMoveTo(boxLocation.left + 40, boxLocation.top + 50);
			eventSender.mouseDown();
			eventSender.mouseUp();

			eventSender.mouseMoveTo(boxLocation.left + boxLocation.width - 40, boxLocation.top + boxLocation.height - 40);
			eventSender.mouseDown();
			eventSender.mouseUp();
		}
	}

	var events = [ "mouseover", "mouseout", "click" ],
		regionChild = document.querySelector("#region p"),
		content = document.querySelector("#source p");

	events.forEach(function(item) {
		regionChild.addEventListener(item, regionChildEventHandler);
		content.addEventListener(item, contentEventHandler);
	})

	runScriptedTest();
	</script>
</body>
</html>